<cfsetting requestTimeOut = "5000"> 

<cfscript>    
    view = createObject("component", session.rootDir & ".views.layout");
    if( Session.Auth EQ True and (Session.strAuthType EQ Session.MANAGERS or Session.strAuthType EQ Session.IT or Session.strAuthType EQ Session.HR or Session.Manager) ){
        view.init("Contractor Expiration Date Review Master Page", 
        "/jquery/ui-1.8.5/jquery-ui.min.js,/jquery/plugins/scrollTo/jquery.scrollTo-1.4.2-min.js, /#session.rootDir#/static/js/NonSCF/MasterReview.js",
        "/jquery/ui-1.8.5/themes/cupertino/jquery-ui.css","Home",index, "Termination");
    }else{
        view.init("Denied","","","Home","Denied");
    }    
    view.html();
</cfscript>

<cffunction name="index" access="public" output="true" returntype="any">
    <cfscript>
        import models.*;
        FormActionExtend = '/#session.rootDir#/controller/SubmitHandlerTermination.cfm?NonSCFADAccount=extend';
        FormActionTerminate = '/#session.rootDir#/controller/SubmitHandlerTermination.cfm?NonSCFADAccount=terminate';
        KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");
        AD = CreateObject("component", "code_lib.SCF_ActiveDirectory");
        PS = CreateObject("component", "code_lib.SCF_Powershell");
        //NonSCFMasters = ORMExecuteQuery("FROM RosettaStone r WHERE r.Disabled = 0 AND r.NonSCFMasterID IS NOT NULL");
        NonSCFMasters = ORMExecuteQuery("FROM NonSCFMaster n WHERE n.NonSCFTypeID >= 2 ");
    </cfscript>
    
    <cfoutput>
    <h1 class="title">Contractor Expiration Date Review Master Page</h1>
    <div class="entry">
        Welcome, #Session.EmpInfo.FirstName# #Session.EmpInfo.LastName#. 
        On this page, you'll be allowed to extend the expiration date for those 
        contractors that directly report to you.&nbsp;&nbsp;Accounts will expire 
        at the end of every month.&nbsp;&nbsp;To extend the operating window for 
        an additional month, select the option in the "Extend" column.&nbsp;
        &nbsp;There is a two week window prior to the end of each month where 
        this option will be available to you.&nbsp;&nbsp;If the contractor is no 
        longer with SCF, please select the "Terminate" option.&nbsp;&nbsp;If 
        there are additional contractors that report directly to you that are 
        not represented here, please contact the Service Desk at x5200.
        <br /><br />
        
        <cfform name="frmReview" method="post">
            <table  cellpadding="1" cellspacing="" width="100%">
                <tr>
                    <td><strong>Contractor Name</strong></td>
                    <td><strong>Manager Name</strong></td>
                    <td><strong>Expiration Date</strong></td>
                    <td><strong>Extend</strong></td>
                    <td><strong>Terminate*</strong></td>                
                </tr>
                
                <cfloop from="1" to="#ArrayLen( NonSCFMasters )#" index="i" >
                <!---<cfloop from="1" to="100" index="i" >--->
                    <cfset Rosetta = ORMExecuteQuery("FROM RosettaStone WHERE Disabled = 0 AND NonSCFMasterID = #NonSCFMasters[i].getNonSCFMasterID()#") />
                    <cfif ArrayLen(Rosetta) GTE 1>                        
                        <cfset EmployeeUserAccount = Rosetta[1].getUserAccount() />
                        <cfset EmployeeDN = AD.getUserDNByAccountName( EmployeeUserAccount ) />
                        
                        <cfif EmployeeDN NEQ "">                        
                                
                        	<cftry>
                            	<cfset EmployeeAD = AD.getUserAttributesByDN( EmployeeDN, 'displayname, sAMAccountName, manager, department, title, company, distinguishedName, accountExpires') />
	                            <cfset Manager = AD.getUserAttributesByDN( EmployeeAD.manager, 'displayname, sAMAccountName, manager, department, title, company, distinguishedName, accountExpires') />
	                            <cfset Title = EmployeeAD.title />
                                <tbody id="#Rosetta[1].getNonSCFMasterID()#">
    	                            <cftry>
    	                                <cfset ExpirationDate = PS.usePowerShell('[dateTime]::FromFileTime($(#EmployeeAD.accountExpires#))') />
    	                                <cfset ExpirationDate = DateFormat(ExpirationDate, 'mm/dd/yyyy') />    
                                        <cfinput type="hidden" name="ExpirationDate" value="#ExpirationDate#">                
    	                            <cfcatch type="Any" >
    	                                <cfset ExpirationDate = '[Error]' />
                                        <cfinput type="hidden" name="ExpirationDate" value="#ExpirationDate#">
    	                            </cfcatch>
    	                            </cftry>
    	                            <cfinput type="hidden" name="EmployeeUserAccount" value="#EmployeeUserAccount#">
    	                            <cfinput type="hidden" name="EmployeeDN" value="#EmployeeDN#">	                            
	                                <tr>
	                                    <td>#EmployeeAD.displayname#</td>
	                                    <td>#Manager.displayname#</td>
	                                    <td>#ExpirationDate#</td>
	                                    <td align="center">
	                                        <cfif ExpirationDate NEQ '[Error]'>
	                                            <cfinput type="radio" name="ExtendTerminate#Rosetta[1].getNonSCFMasterID()#" value="1" class="extend" />
	                                        <cfelse>
	                                            <strong class="error">NA</strong>
	                                        </cfif>
	                                    </td>
	                                    <td align="center">
	                                        <cfinput type="radio" name="ExtendTerminate#Rosetta[1].getNonSCFMasterID()#" value="2" class="terminate" />                                
	                                    </td>
	                                </tr>
	                            </tbody>                            
                            <cfcatch type="Any" >
                            </cfcatch>
                            </cftry>
                            
                           

                        </cfif>
                    </cfif>
                    
                    <!---<tbody id="#NonSCFMasters[i].getNonSCFMasterID()#">
                        <tr>
                            <td>#NonSCFMasters[i].getFirstName()# #NonSCFMasters[i].getLastName()#</td>
                            <td>#NonSCFMasters[i].getSupervisor()#</td>
                            <td>
                                <!---if cfcatch throws error, cf cant find/display account--->
                                <cfset error = 0 />
                                <cftry>
                                	<cfset UserAccount = ListGetAt(NonSCFMasters[i].getEmail(), 1, '@') />
                                    <cfset UserDN = AD.getUserDNByAccountName( UserAccount ) />
                                    <cfset EmployeeAD = AD.getUserAttributesByDN( UserDN, 'accountExpires') />
                                    <cfset EmployeeAD = PS.usePowerShell('[dateTime]::FromFileTime($(#EmployeeAD.accountExpires#))') />                                    
                                    <cfinput type="hidden" name="UserAccount" value="#UserAccount#">
                                    <cfinput type="hidden" name="UserDN" value="#UserDN#">
                                    <cfinput type="hidden" name="ExpirationDate" value="#DateFormat(EmployeeAD, 'mm/dd/yyyy')#">
                                    #DateFormat(EmployeeAD, 'mm/dd/yyyy')#
                                <cfcatch type="Any" >
                                    [None]
                                    <cfset error = 1 />
                                </cfcatch>
                                </cftry>
                            </td>
                            <td align="center">
                                <cfif error EQ 0>
                                    <cfinput type="radio" name="ExtendTerminate#NonSCFMasters[i].getNonSCFMasterID()#" value="1" class="extend" />
                                <cfelse>
                                    <strong class="error">NA</strong>
                                </cfif>
                            </td>
                            <td align="center">
                                <cfinput type="radio" name="ExtendTerminate#NonSCFMasters[i].getNonSCFMasterID()#" value="2" class="terminate" />                                
                            </td>
                        </tr>
                    </tbody>--->
                </cfloop>
                <tr>
                    <td colspan="5" align="right">&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="5" align="right">
                        <cfinput type="button" name="Clear" value="Clear" />
                        <cfinput type="button" name="Submit" value="Submit" />
                        <cfinput type="hidden" name="FormActionExtend" value="#FormActionExtend#">
                        <cfinput type="hidden" name="FormActionTerminate" value="#FormActionTerminate#">
                    </td>
                </tr>
            </table>
        </cfform>
    </div>
    </cfoutput>
    
</cffunction>